//
//  LoginModel.swift
//
//  Created by Icy on 2017/1/11
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import ModelProtocol

 class LoginModel: ModelProtocol {

    // MARK: Declaration for string constants to be used to decode and also serialize.
	internal let kLoginUserKey: String = "user"
	internal let kLoginMessageKey: String = "message"
	internal let kLoginTokenKey: String = "token"
	internal let kLoginSuccessKey: String = "success"


    // MARK: 属性
	 var user: UserModel!
	 var message: MessageModel!
	 var token: String!
	 var success: Bool = false


    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
		user = UserModel(json: json[kLoginUserKey])
		message = MessageModel(json: json[kLoginMessageKey])
		token = json[kLoginTokenKey].stringValue
		success = json[kLoginSuccessKey].boolValue

    }


    /**
    Generates description of the object in the form of a NSDictionary.
    - returns: A Key value pair containing all valid values in the object.
    */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {

        var dictionary: [String : AnyObject ] = [ : ]
		if user != nil {
			dictionary.updateValue(user!.dictionaryRepresentation() as AnyObject, forKey: kLoginUserKey)
		}
		if message != nil {
			dictionary.updateValue(message!.dictionaryRepresentation() as AnyObject, forKey: kLoginMessageKey)
		}
		if token != nil {
			dictionary.updateValue(token! as AnyObject, forKey: kLoginTokenKey)
		}
		dictionary.updateValue(success as AnyObject, forKey: kLoginSuccessKey)

        return dictionary
    }


}
